package demo2;

import java.util.Random;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-08-02
 * Time: 9:38
 */

class MyTherad extends Thread{

    private long sum = 0;
    private  int[] arr;

    public MyTherad(){
        arr = new int[10000000];
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100) + 1;
        }
    }

    @Override
    public void run() {
        int sum = 0;
        for (int i = 1; i < arr.length; i += 2) {
            sum += arr[i];
        }
        this.sum = sum;
    }

    public int[] getArr(){
        return arr;
    }

    public long getSum(){
        return sum;
    }

}

public class Test {
    public static void main(String[] args) throws InterruptedException {
        long time1 = System.currentTimeMillis();
        MyTherad therad = new MyTherad();
        therad.start();
        int[] arr = therad.getArr();
        long sum = 0;
        for (int i = 0; i < arr.length; i += 2) {
            sum += arr[i];
        }
        therad.join();
        sum += therad.getSum();
        long time2 = System.currentTimeMillis();
        System.out.println(sum);
        System.out.println(time2 - time1);
    }
}
